/**
 * @file sq_test.cpp
 * @brief test sqList function
 * @author liwanglin (lwl510ll@163.com)
 * @version 1.0
 * @date 2021-09-03
 * 
 * @copyright Copyright (c) 2021  liwanglin
 * 
 */
#include "sq_list.h"
#include <iostream>

using namespace std;

int main()
{
    int val, pos;
    SqList sqListTest = SqList();

    // 使用头插法创建初始化链表
    sqListTest.CreateHead(5);
    cout << "The sqList length " << sqListTest.ListLength() << endl;
    sqListTest.PrintAllValue();

    // 获取链表中指定位置的值
    pos = 2;
    sqListTest.GetPosValue(pos, &val);
    cout << "pos: " << pos << " val: " << val << endl;

    // 查询链表中某个值所在的位置
    val = 2;
    sqListTest.QueryValue(val, &pos);
    cout << "val: " << val << " pos: " << pos << endl;

    // 删除链表中指定位置的值
    pos = 2;
    sqListTest.DeletePos(2);
    sqListTest.PrintAllValue();

    // 在指定位置插入一个节点
    pos = 2;
    val = 4;
    sqListTest.InsertNode(pos, val);
    sqListTest.PrintAllValue();

    // 测试链表的排序功能
    SqList *sortListTest = SqList::SortSqList(&sqListTest);
    sortListTest->PrintAllValue();

    int temp_int = 10;
    elem data[temp_int] = {3, 4, 1, 13, 12, 15, 22, 21, 17, 20};
    for(int i=1; i<temp_int+1; i++)
    {
        sortListTest->InsertNode(i, data[i-1]);
    }
    sortListTest->PrintAllValue();

    SqList *sortListTest1 = SqList::SortSqList(sortListTest);
    sortListTest1->PrintAllValue();

    return 0;
}